<template>
	<view>
		<view class=""
			style="width: 90%;padding-top: 60rpx; margin: auto; height: 100rpx; display: flex; align-items: center; ">
			<image @click="toReturn" style="width: 50rpx; height: 50rpx;" src="../../../static/images/goBack.png">
			</image>
			<span style="margin-left: 20rpx;">求书</span>
		</view>
		<view class="">
			<view class="" style=" width: 90%; margin: auto;">
				<p style="font-weight: 600;">信息录入</p>
				<view class=""
					style=" padding: 20rpx 0 ; display: flex; align-items: center;border-bottom: 1px solid #ccc;">
					<span>书名：</span>
					<input class="uni-input" placeholder="请输入" v-model="inpuTtitle" />
				</view>
				<view class=""
					style=" padding: 20rpx 0 ; display: flex; align-items: center;border-bottom: 1px solid #ccc;">
					<span>作者：</span>
					<input class="uni-input" placeholder="请输入" v-model="inputAuthor" />
				</view>
				<view class=""
					style=" padding: 20rpx 0 ; display: flex; align-items: center;border-bottom: 1px solid #ccc;">
					<span>主角：</span>
					<input class="uni-input" placeholder="请输入" v-model="inputLead " />
				</view>
				<view class=""
					style=" padding: 20rpx 0 ; display: flex; align-items: center;border-bottom: 1px solid #ccc;">
					<span>联系方式：</span>
					<input class="uni-input" placeholder="请输入" v-model="inputPhone" />
				</view>
			</view>
			<view class="" style="width: 90%; margin: 30rpx auto; ">
				<button @click="tosave()"
					style=" color: #fff; border-radius: 50rpx; border: 2rpx solid #f67d34;background: linear-gradient(to right, #f67d34, #e5574b);">保存</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyNeedbook
	} from '@/http/api.js'
	export default {
		data() {
			return {
				inpuTtitle:'', //标题
				inputAuthor:'', //作者
				inputLead:'', //主角
				inputPhone:'', //手机号

			};
		},
		onLoad() {
			// this.MyNeedbook()
		},
		methods: {

			MyNeedbook() {
				
				if (this.inpuTtitle && this.inputAuthor && this.inputPhone && this.inputLead ) {
				  this.userInfo = uni.getStorageSync('userInfo');
				  let data = {
				  	"token": this.userInfo.userinfo.token, //用户token
				  	"title": this.inpuTtitle, //标题
				  	"author": this.inputAuthor, //作者
				  	"phone": this.inputPhone, //电话号
				  	"lead": this.inputLead //主角
				  
				  }
				  getMyNeedbook(data).then((res) => {
				  	 
				  	console.log(res[1].data, "听书");
				  	if (res[1].data.code == 1) {
				  		uni.showToast({
				  			title: '保存成功',
				  			duration: 2000
				  		});
				  		    this.inpuTtitle = '', //标题
				  			this.inputAuthor = '', //作者
				  			this.inputPhone = '', //电话号
				  			this.inputLead = '' //主角
				  
				  	}
				  })
				 } else {
				   // 当存在参数为空时给出相应的提示或处理
				   uni.showToast({
				   	title: '请填写完整的信息',
				   	duration: 2000,
					icon:"none"
				   });
				   console.log('请填写完整的信息');
				 }
			
			},
			// 保存
			tosave() {
				this.MyNeedbook()
			},
			// 返回上一页
			toReturn() {
				uni.navigateBack();
			},
		}
	}
</script>

<style lang="scss">
	.uni-input {
		width: 70%;

	}
</style>